﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;

namespace Piao
{
    static class ImageUtil
    {
        public static void GrayImage(ref Image img)
        {
            Bitmap bmp = new Bitmap(img);

            int height = bmp.Height;
            int width = bmp.Width;
            
            for (int x = 0; x < width; x++)
            {
                for (int y = 0; y < height; y++)
                {
                    Color c = bmp.GetPixel(x, y);
                    int rgb = Convert.ToInt32((double)(((0.7 * c.R) + (0.2 * c.G)) + (0.1 * c.B)));

                    //if (rgb < 150) rgb = 0;
                    //if (rgb >= 150) rgb = 255;

                    bmp.SetPixel(x, y, Color.FromArgb(rgb, rgb, rgb));
                }
            }

            img = (Image)bmp;
        }


    }
}
